<?php
namespace frontend\controllers;

use frontend\models\SmsCodeModel;
use Yii;
use yii\data\Pagination; //分页
use frontend\base\BaseController;
use frontend\utils\UrlUtil;
use frontend\utils\CurlUtil;

/**
 * Site controller
 */
class CookController extends BaseController
{
    /**
     * 欢迎页
     * @return string
     */
    public function actionDemo()
    {
        echo '测试成功,欢迎使用!!!'.'<br><br><br>';
        echo "['cook-list'=>'传参数name，搜name相关菜谱']
                <a href='/cook/cook-list?name=菜' target='_blank' style='text-decoration:none;'>   去查菜谱 >></a>".'<br>';
    }

    //菜谱清单
    public function actionCookList()
    {
        Yii::$app->layout = false;
        $name = $this->post('name');
        // $name = '西红柿';
        $url = Yii::$app->params['api_cook_url'].'?key='.Yii::$app->params['api_key'];
        $query['dtype'] = 'json';
        $query['menu'] = $name;
        $result = CurlUtil::getInstance()->post($url, $query);
        $result = json_decode($result, true);
        if($result['resultcode'] == 200){
            $result = !empty($result['result']) ? $result['result']['data'] : [];
        }
        return $this->render('cook-list',['list'=>$result]);
    }

}